home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 5163 < prev    next >
Encoding:
Text File  |  1996-08-05  |  898 b   |  42 lines

  1. Path: news.ox.ac.uk!kinder
  2. From: kinder@teaching.physics.ox.ac.uk (David Kinder)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: varying-length argument list
  5. Date: 11 Mar 96 11:03:26 GMT
  6. Organization: Oxford University
  7. Message-ID: <4i11d3$idm@news.ox.ac.uk>
  8. References: <549.6641T218T2207@zedat.fu-berlin.de>
  9. NNTP-Posting-Host: teaching1.physics.ox.ac.uk
  10. X-Newsreader: TIN [version 1.2 PL0]
  11.  
  12. crayor (crayor@zedat.fu-berlin.de) wrote:
  13. : Is there any way to code it in C?
  14. : Using va_arg() would mean that I have to recode sprintf(), right?
  15.  
  16. What you need is vsprintf(). To give an example using vprintf() (but the same
  17. idea):
  18.  
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21.  
  22. void MyPrintf(const char *format,...);
  23.  
  24. int main()
  25. {
  26.     MyPrintf("Testing: %d %d %d...\n",1,2,3);
  27.     return 0;
  28. }
  29.  
  30. void MyPrintf(const char *format,...)
  31. {
  32. va_list ap;
  33.  
  34.     va_start(ap,format);
  35.     vprintf(format,ap);
  36.     va_end(ap);
  37. }
  38.  
  39.  
  40. David
  41.  
  42.